import { Exception } from "sass"
import { SheetItem } from "./answer_sheet"

interface Option{
    key:string
    value:string
}

interface Question{
    id:number
    title:string
    options:Option[]
    answer:string
    restore:string
    explain:string
    question_type:number
    subject_name:string
    number:string
    user_answer:string
}

async function get_question(qid:number){
    qid=qid?qid:Math.floor(Math.random()*100)+100
    const api='http://127.0.0.1:8000/question/'+qid
    const res= await fetch(api)
    return await res.json()
}

const EmptyQuestion:Question={
    id:-1,
    title:'请在题库中选择试题！',
    options:[],
    answer:'',
    restore:'',
    explain:'',
    question_type:1,
    subject_name:'',
    number:'',
    user_answer:''
}

async function update_answer(question_id:number,is_right:boolean) {
    const api=`http://127.0.0.1:8000/answersheet/update/${question_id}?is_right=${is_right}`
    const res=await fetch(api)
    return (await res.json()) as SheetItem
}

export {Question,Option,EmptyQuestion,get_question,update_answer}